package com.controller.manage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.UserZJ;
import com.service.manage.RoleService;
import com.service.manage.UserRegisterService;
import com.service.manage.UserRoleService;
import com.service.manage.UserService;
import com.service.manage.UserZJService;

@Controller
@RequestMapping("/jsp/manager")
public class UserZJController {
    @Resource(name = "userZJServiceImp")
    private UserZJService userZJService;
    @Resource(name = "userRegisterServiceImp")
    private UserRegisterService userRegisterService;
    @Resource(name = "userRoleServiceImp")
    private UserRoleService userRoleService;
    @Resource(name = "roleServiceImp")
    private RoleService roleService;
    @Resource(name = "userServiceImp")
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/getUserZJList")
    public Map<String, Object> getUserZJList(UserZJ userzj, Integer page, Integer rows) {
	userzj.setPage(((page - 1) * rows));
	userzj.setRows(rows);
	// System.out.println(userzj.getPage()+" "+userzj.getRows());

	List<UserZJ> list = userZJService.getUserZJList(userzj);
	int count = userZJService.getUserZJCount(userzj);
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("rows", list);
	map.put("total", count);
	return map;
    }

    @ResponseBody
    @RequestMapping(value = "/deleteUserZJ")
    public int deleteUserZJ(@RequestParam("userzj_id") String userzjid) {
	int i = userRegisterService.deleteUserRegister(userzjid);
	return i;
    }

    @ResponseBody
    @RequestMapping(value = "/deleteUserZJList")
    public int delUserZJList(String userzjids) {
	String[] userzjid = userzjids.split(",");
	int result = userRegisterService.deleteUserRegisterList(userzjid);
	return result;
    }

    // @Transactional(rollbackFor=Exception.class)
    @ResponseBody
    @RequestMapping(value = "/addUserZJ")
    public int addUserZJ(UserZJ userzj) {
	userzj.setUserzj_experience(userzj.getUserzj_experience().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	userzj.setUserzj_remark(userzj.getUserzj_remark().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	userzj.setUserzj_result(userzj.getUserzj_result().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	int i = userZJService.addUserZJ(userzj);
	return i;
    }

    @ResponseBody
    @RequestMapping(value = "/updateUserZJ")
    public int updateUserZJ(UserZJ userzj) {
	userzj.setUserzj_experience(userzj.getUserzj_experience().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	userzj.setUserzj_remark(userzj.getUserzj_remark().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	userzj.setUserzj_result(userzj.getUserzj_result().replace(" ", "&nbsp").replace("\r\n", "<br>"));
	int i = userZJService.updateUserZJ(userzj);
	return i;
    }

}
